package com.em.sugarfight.entity;

import java.util.LinkedHashMap;
import java.util.Map;

public class FixedSizeContainer<T> {
    private final LinkedHashMap<T, Boolean> map;
    private final int maxSize;

    public FixedSizeContainer(int maxSize) {
        this.maxSize = maxSize;
        this.map = new LinkedHashMap<T, Boolean>(maxSize, 0.75f, false) {
            @Override
            protected boolean removeEldestEntry(Map.Entry<T, Boolean> eldest) {
                return size() > maxSize;
            }
        };
    }

    public void add(T element) {
        map.put(element, Boolean.TRUE);
    }

    public boolean contains(T element) {
        return map.containsKey(element);
    }

    public int size(){
        return map.size();
    }
}